{% extends "admin/layout.html" %}
{% block admin_body %}
  <h1>Manage Users</h1>
  <p>
    All uses with "master" privileges can give and revoke permissions
    from this page. You cannot change the passwords of other users and
    remove your own user or "master" privilege. Privileges are separated
    by commas &mdash; optional whitespace is ignored.
  </p>
  <p><strong>Privileges</strong></p>
  <ul>
    <li><tt>master</tt> &mdash; user can create and edit user accounts.</li>
    <li><tt>frozenpassword</tt> &mdash; user cannot change his password.</li>
  </ul>
  <form action="" method="post">
    {% if ask_confirmation %}
      <div class="dialog">
        <h2>Confirm</h2>
        <div class="text">
          {% trans amount=to_delete|length %}
            Do you really want to delete the user?
          {% pluralize %}
            Do you really want to delete {{ amount }} users?
          {% endtrans %}
        </div>
        <div class="buttons">
          <input type="hidden" name="update" value="yes">
          <input type="submit" name="confirmed" value="Yes">
          <input type="submit" name="aborted" value="No">
        </div>
      </div>
    {% endif %}
    {% if generated_user and generated_password %}
    <div class="dialog">
      <h2>User Generated</h2>
      <div class="text">
        The user <strong>{{ generated_user|e }}</strong> was generated successfully
        with the password <strong>{{ generated_password|e }}</strong>.
      </div>
    </div>
    {% endif %}
    {% if user_exists %}
    <div class="dialog">
      <h2>Username in User</h2>
      <div class="text">
        The username {{ user_exists|e }} is in use. Select a different one.
      </div>
    </div>
    {% endif %}
    {% if self_destruction %}
    <div class="dialog">
      <h2>Error</h2>
      <div class="text">
        You can't delete your own user or remove your own master privileges.
      </div>
    </div>
    {% endif %}
    {% if add_user_mode %}
    <div class="dialog detail_form">
      <h2>Add User</h2>
      <div class="text">
        Username <input type="text" size="24" name="username" value="{{
          form.username|e(true) }}">
      </div>
      <div class="buttons">
        <input type="submit" name="add_user" value="Add">
        <input type="submit" name="aborted" value="Cancel">
      </div>
    </div>
    {% endif %}
    <table class="mapping">
      <tr>
        <th>Username</th>
        <th>Privileges</th>
        <th class="actions">Delete</th>
      </tr>
      {%- for user, privileges in users|dictsort %}
      <tr>
        <td class="username">{{ user|e }}</td>
        <td class="groups"><input type="text" name="privileges-{{ user|e }}" value="{{ privileges|join(', ') }}"></td>
        <td class="actions"><input type="checkbox" name="delete" value="{{ user|e
        }}"{% if user in to_delete %} checked{% endif %}></td>
      </tr>
      {%- endfor %}
    </table>
    <div class="actions">
      <input type="submit" name="update" value="Update">
      <input type="submit" name="add_user" value="Add User">
      <input type="submit" name="cancel" value="Cancel">
    </div>
  </form>
{% endblock %}
